<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <!-- import CSS -->
  <link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.9/theme-chalk/index.css">
  <style>
    .center{
      width: 1200px;
      margin: 0 auto;
    }
    .scale{
      text-decoration: none;
      color: #666;
    }
    .scale:hover {
      transform: scale(1.2);
      transition-duration: .3s;
    }
    .scale:active{
      color: orange;
    }

    h3{color: white}
    .el-card p.active,.el-card p:hover{
      color:#409EFF
    }
  </style>
</head>
<body>
<div id="app">
  <common-header></common-header>
  <el-container style="background-color: rgb(241,242,243)">

    <el-main >
      <el-row gutter="20">
        <el-col span="4">
          <el-card style="height: 500px">
            <p class="active">个人信息</p>
            <p @click="location.href='articleManagement.html'">稿件管理</p>
          </el-card>
        </el-col>
        <el-col span="20">
          <el-card  style="height: 500px">
            <el-form label-width="100px" class="right-cont-wrap">
              <el-form-item label="头像">
                <img v-show="url==''" :src="userInfo.imgUrl" style="float:left;width: 145px;height: 145px;border-radius: 10px;background-color: #666" alt="">
                <el-upload style="float: left"
                           action="/api/file/upload"
                           name="picFile"
                           limit="1"
                           list-type="picture-card"
                           :on-preview="handlePictureCardPreview"
                           :on-success="handleSuccess"
                           :fileList="fileList"
                           :on-remove="handleRemove">
                  <i class="el-icon-plus"></i>
                </el-upload>
                <el-dialog :visible.sync="dialogVisible">
                  <img width="100%" :src="dialogImageUrl" alt="">
                </el-dialog>
              </el-form-item>
              <el-form-item label="昵称">
                <el-input
                        type="text"
                        placeholder="请输入昵称"
                        v-model="userInfo.nickName"
                        style="width:190px"
                ></el-input>
              </el-form-item>

              <el-form-item label="用户名">
                <el-input
                        type="text"
                        placeholder="请输入用户名"
                        v-model="userInfo.userName"
                        style="width:190px"
                        disabled
                ></el-input>
              </el-form-item>

              <!--<el-form-item label="密码">
                <div class="el-btn" @click="dialogVisible=true">修改</div>
              </el-form-item>-->




              <el-form-item label="">
                  <el-button type="primary" @click="save">保存信息</el-button>
              </el-form-item>
            </el-form>
          </el-card>
        </el-col>
      </el-row>


    </el-main>
  </el-container>
  <common-footer></common-footer>
</div>
</body>
<!--引入axios和vue框架文件-->
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>

<!-- import Vue before Element -->
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<!-- import JavaScript -->
<script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>
<script src="js/common.js"></script>
<script>
  let v = new Vue({
    el: '#app',
    data: function () {
      return {
        url:'',
        userInfo: getLocalUser()||{},
        fileList:[],//图片列表
        dialogImageUrl: '',
        dialogVisible: false,


      }
    },
    methods: {

      save(){
        if (v.url!=''){
          v.userInfo.imgUrl = v.url;
        }
        axios.post("/api/user/update",v.userInfo).then(function (response) {
        v.$message({
            message: '操作成功！',
            type: 'success'
          });
          localStorage.localUser = JSON.stringify(v.userInfo);
        })
      },
      hdNavHandleSelect(key, keyPath) {
      },
      handleRemove(file, fileList) {
        v.url="";
        console.log(file, fileList);
        //发出删除文件的请求
        axios.get("/api/file/remove?url="+file.response).then(function (response) {
          console.log("删除完成!");
        })
      },
      handlePictureCardPreview(file) {
        this.dialogImageUrl = file.url;
        this.dialogVisible = true;
      },
      handleSuccess(response,file,fileList){
        v.url = response;
      },

    },
    created:function () {
    }
  })
</script>
</html>